<?php
/**
* @file $Id: Search.php 437 2007-04-23 00:57:51Z focus-sis $
* @package Focus/SIS
* @copyright Copyright (C) 2006 Andrew Schmadeke. All rights reserved.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.txt
* Focus/SIS is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.txt for copyright notices and details.
*/

if($_REQUEST['modname']=='Users/Search.php')
{
	ProgramTitle();
	DrawHeader(_('Find a User'));
}

if(User('PROFILE')=='admin' && ($_REQUEST['modname']!='Users/User.php' || AllowUse('Users/User.php')))
{
	if($_REQUEST['modfunc']=='search' || !$_REQUEST['modfunc'])
	{
		if($_SESSION['staff_id'])
		{
			unset($_SESSION['staff_id']);
			echo '<script language=JavaScript>parent.side.location="'.$_SESSION['Side_PHP_SELF'].'?modcat="+parent.side.document.forms[0].modcat.value;</script>';
		}

		echo '<BR>';
		if($extra)
			$user = ucwords($extra);
		else
			$user = _('User');
		PopTable('header','Find a '.$user);

		echo "<FORM action=Modules.php?modname=$_REQUEST[modname]&modfunc=list&next_modname=$_REQUEST[next_modname] method=POST>";
		echo '<TABLE>';
		echo '<TR><TD align='.ALIGN_RIGHT.'>'._('Last Name').'</TD><TD><INPUT type=text name=last></TD></TR>';
		echo '<TR><TD align='.ALIGN_RIGHT.'>'._('First Name').'</TD><TD><INPUT type=text name=first></TD></TR>';
		echo '<TR><TD align='.ALIGN_RIGHT.'>'._('Username').'</TD><TD><INPUT type=text name=username></TD></TR>';
		$options = array(''=>_('N/A'),'teacher'=>_('Teacher'),'admin'=>_('Administrator'),'parent'=>_('Parent'),'none'=>_('No Access'));
		if($extra)
			$options = array($extra=>$options[$extra]);

		echo '<TR><TD align='.ALIGN_RIGHT.'>'._('Profile').'</TD><TD><SELECT name=profile>';
		foreach($options as $key=>$val)
			echo '<OPTION value="'.$key.'">'.$val;
		echo '</SELECT></TD></TR>';
		echo '<TR><TD colspan=2 align=center>';
		echo '<BR>';
		if(User('PROFILE')=='admin')
			echo '<INPUT type=checkbox name=_search_all_schools value=Y'.(Preferences('DEFAULT_ALL_SCHOOLS')=='Y'?' CHECKED':'').'><font color=black>'._('Search All Schools').'</font><BR>';
		echo Buttons(_('Submit'),_('Reset'));
		echo '</TD></TR>';
		echo '</TABLE>';
		echo '</FORM>';
		PopTable('footer');
	}

	if($_REQUEST['modfunc']=='list')
	{
		if(!$_REQUEST['next_modname'] || $_REQUEST['next_modname']=='Users/Search.php')
			$_REQUEST['next_modname'] = 'Users/User.php';

		DrawHeader(_('Choose A User'));
		$extra['functions'] = array('PROFILE_ID'=>'_getProfile');
		$staff_RET = GetStaffList($extra);
		$columns = array('FULL_NAME'=>_('User'),'PROFILE_ID'=>_('Profile'));
		$link['FULL_NAME']['link'] = "Modules.php?modname=$_REQUEST[next_modname]";
		$link['FULL_NAME']['variables'] = array('staff_id'=>'STAFF_ID');
		ListOutput($staff_RET,$columns,_('User'),_('Users'),$link);
	}
}
elseif(AllowUse('Users/Preferences.php'))
{
	$_REQUEST['modname'] = "Users/Preferences.php";

	$modcat = 'Users';
	include("modules/$_REQUEST[modname]");
}

function _getProfile($profile_id,$name='')
{	global $THIS_RET,$profiles_RET;

	if(!is_array($profiles_RET))
		$profiles_RET = DBGet(DBQuery("SELECT TITLE,ID FROM USER_PROFILES"),array(),array('ID'));
	if($profile_id)
		return $profiles_RET[$profile_id][1]['TITLE'];
	else
	{
		switch($THIS_RET['PROFILE'])
		{
			case 'admin';
				return _('Administrator with custom permissions');
			break;
			case 'teacher':
				return _('Teacher with custom permissions');
			break;
			case 'parent':
				return _('Parent with custom permissions');
			break;
			case 'none':
				return _('No Access');
			break;
		}
	}
}

?>
